import type { CommonState, PageReq, PageRes } from '../common/commonApi'
import { useApi } from '@/composables/useApi'

export const AccountTypes = [
  { label: '管理员账号', value: 'ADMIN', tagColor: 'green' },
  { label: '普通账号', value: 'NORMAL', tagType: 'primary' },
  { label: '系统账号', value: 'SYSTEM', tagType: 'warning' },

] as const
export type AccountType = typeof AccountTypes[number]['value']
export const AccountResetTypes = [
  { label: '默认密码', value: 'DEFAULT' },
  { label: '随机密码', value: 'RANDOM' },
  { label: '指定密码', value: 'CUSTOM' },

] as const
export type AccountResetType = typeof AccountResetTypes[number]['value']
export const NotifyTypes = [
  { label: '邮件通知', value: 'EMAIL' },
  { label: '短信通知', value: 'SMS' },
] as const
export type NotifyType = typeof NotifyTypes[number]['value']

export interface SystemAccountQuery extends PageReq {
  id?: number
  appType?: string
  username?: string
  nickname?: string
  type?: AccountType
  state?: CommonState
  phone?: string
  email?: string
}

export interface SystemAccount {
  id: number
  appType: string
  username: string
  nickname: string
  type: AccountType
  state: CommonState
  phone: string
  email: string
  avatarId: number
  avatarUrl: string
  roleCodes: string[]
}

export interface AccountResetPwdCmd {
  accountId: number
  type: 'LOGIN'
  resetType: AccountResetType
  password?: string
}

const basePath = '/system/account'
export const accountApi = {
  queryPage: useApi<SystemAccountQuery, PageRes<SystemAccount>>(`${basePath}/page`).get,
  findDetail: async (id: number) => useApi<any, SystemAccount>(`${basePath}/${id}`).get(),
  create: useApi<SystemAccount, SystemAccount>(`${basePath}`).post,
  modify: useApi<SystemAccount, SystemAccount>(`${basePath}`).patch,
  remove: async (id: number) => useApi<null, SystemAccount>(`${basePath}/${id}`).remove(),
  resetPwd: useApi<AccountResetPwdCmd, null>(`${basePath}/resetPwd`).post,
  accountLogout: async (id: number) => useApi<null, SystemAccount>(`${basePath}/${id}/logout`).post(),
}
